Colors


In [1]:
using Color

In [4]:
HSV(160, 0.8, 0.5)


Out[4]:

In [8]:
[ HSV(h, 1, 1) for h in 0:20:340 ]


Out[8]:

In [7]:
[ HSV(0, s, 1) for s in 0:.08:1 ]


Out[7]:

In [9]:
[ HSV(0, 1, v) for v in 0:.08:1 ]


Out[9]:

In [10]:
convert(RGB, HSV(160, 0.8, 0.5))


Out[10]:

In [11]:
string(_)


Out[11]:
"RGB(0.09999999999999998,0.5,0.3666666666666666)"

In [15]:
# named colors
color("burlywood")


Out[15]:

Drawing with Cairo


In [12]:
using Cairo
using Base.Graphics

In [31]:
# a convenient utility for setting up Cairo drawings with an initial fill color and coordinate system
# the result is a graphics context you can draw to
function drawing(w,h; fill=nothing, coords=nothing, left=0, right=w, top=0, bottom=h, surface=CairoRGBSurface(w, h))
    gc = creategc(surface)
    if coords != nothing
        left, right, top, bottom = coords
    end
    set_coords(gc, 0, 0, w, h, left, right, top, bottom)
    if fill != nothing
        set_source(gc, fill)
        paint(gc)
    end
    set_source(gc, RGB(0,0,0))
    gc
end


Out[31]:
drawing (generic function with 1 method)

In [32]:
d = drawing(275, 250; fill=color("burlywood"), left=0, right=1, top=1, bottom=0)


Out[32]:
CairoContext(Ptr{Void} @0x0000000004c89a60,CairoSurface(Ptr{Void} @0x0000000003710610,275.0,250.0,#undef),Ptr{Void} @0x0000000008684990)

In [25]:
circle(d, 0.5, 0.5, 0.1); stroke(d)

In [26]:
d.surface


Out[26]:

In [27]:
set_source(d, HSV(0, 1, 1))

In [33]:
circle(d, 0.5, 0.2, 0.1); fill(d)

In [29]:
d.surface


Out[29]:

In [30]:
write_to_png(d.surface, "test.png")

In [34]:
function picture(d)
  set_source(d, RGB(0,0,0))
  circle(d, 0.5, 0.5, 0.1); stroke(d)
  set_source(d, HSV(0, 1, 1))
  circle(d, 0.5, 0.2, 0.1); fill(d)
end


Out[34]:
picture (generic function with 1 method)

In [35]:
d = drawing(275, 250; fill=color("burlywood"), left=0, right=1, top=1, bottom=0,
            surface=CairoSVGSurface("test.svg", 275, 250))


Out[35]:
CairoContext(Ptr{Void} @0x0000000006d99660,CairoSurface(Ptr{Void} @0x0000000004855300,275.0,250.0,#undef),Ptr{Void} @0x0000000008684a40)

In [36]:
picture(d); finish(d.surface)

In [ ]: